package com.example.demo.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.redisson.api.RedissonClient;
import org.redisson.solon.RedissonClientOriginalSupplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * Redisson配置类
 *
 * @author raos
 * @date 2024-12-17
 */
@Configuration
public class RedissonConfig {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 创建 redis 客户端 RedissonClient
     */
    @Bean(name = "redissonClient1", typed = true)
    public RedissonClient redissonClient1(@Inject("${redis.ds1}") RedissonClientOriginalSupplier supplier) {
        RedissonClient redissonClient = supplier.get();
        logger.info("redis config1...");
        String yaml = "";
        try {
            yaml = redissonClient.getConfig().toYAML();
        } catch (IOException e) {
            logger.warn("未读取到配置信息1");
        }
        logger.info("{}", yaml);
        return redissonClient;
    }

    @Bean(name = "redissonClient2")
    public RedissonClient redissonClient2(@Inject("${redis.ds2}") RedissonClientOriginalSupplier supplier) {
        RedissonClient redissonClient = supplier.get();
        logger.info("redis config2...");
        String yaml = "";
        try {
            yaml = redissonClient.getConfig().toYAML();
        } catch (IOException e) {
            logger.warn("未读取到配置信息2");
        }
        logger.info("{}", yaml);
        return redissonClient;
    }

}
